let arr = [
  {
    id: 1001,
    name: "张三",
    money: 100,
    children: [
      { id: 1002, name: "张欢欢", money: 200 },
      {
        id: 1010,
        name: "张乐乐",
        money: 100,
        children: [
          { id: 1003, name: "张小欢", money: 300 },
          { id: 1004, name: "张小乐", money: 400 },
        ],
      },
    ],
  },
  {
    id: 1011,
    name: "李四",
    money: 100,
    children: [
      { id: 1005, name: "李红红", money: 500 },
      { id: 1006, name: "李明明", money: 600 },
    ],
  },
];

// let total = 0;

// function f(arr) {
//   arr.forEach((item) => {
//     if (item.children) {
//       return f(item.children);
//     } else {
//       total += item.money;
//     }
//   });
// }

// f(arr);

// console.log(total);

let arr1 = [100, 200, [300, 400, [500, 600]]];

//arr2=[100,200,300,400,500,600]

let arr2 = [];
function demo(arr1,arr2) {
  arr1.forEach((item) => {
    if (typeof item === "number") {
      arr2.push(item);
    } else {
      return demo(item,arr2);
    }
  });
}

demo(arr1,arr2);
console.log(arr2);
